#include "Command/CommandStack.hpp"

CommandStack::CommandStack():curComInd(0)
{
}

void CommandStack::addCommand(Command *com)
{
    if( curComInd  + 1 < (int)commands.size() )
        commands.erase( commands.begin() + (curComInd + 1), commands.end() );
    commands.push_back(com);
    curComInd = commands.size() - 1;
    com->execute();
}

void CommandStack::undo()
{
    if (curComInd!=-1)
        commands[curComInd--]->unexecute();
}

void CommandStack::redo()
{
    if ( (int)commands.size() != curComInd  + 1 )
        commands[++curComInd]->execute();
}
